package com.imooc.config;

import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * FileName: WechatOpenConfig.java
 * Description: TODO
 *
 * @author HuangRI(874668739 @ qq.com)
 * @version 1.0
 * @date 2021/1/4
 */
@Configuration
public class WechatOpenConfig {

    @Autowired
    private WechatAccountConfig wechatAccountConfig;

    @Bean
    public WxMpService wXOpenService(WxMpConfigStorage wxOpenConfigStorage) {
        WxMpService wxOpenService = new WxMpServiceImpl();
        wxOpenService.setWxMpConfigStorage(wxOpenConfigStorage);
        return wxOpenService;
    }

    @Bean
    public WxMpConfigStorage wxOpenConfigStorage() {
        WxMpDefaultConfigImpl wxOpenConfigStorage = new WxMpDefaultConfigImpl();
        wxOpenConfigStorage.setAppId(wechatAccountConfig.getOpenAppId());
        wxOpenConfigStorage.setSecret(wechatAccountConfig.getOpenAppSecret());
        return wxOpenConfigStorage;
    }
}
